<template>
	<div>
		<el-card class="!border-none" v-loading="pager.loading" shadow="never">
			<el-button v-perms="['feedback.feedback_record/delete']" :disabled="!selectData.length"
				@click="handleDelete(selectData)">
				删除
			</el-button>
			<div class="mt-4">
				<el-table :data="pager.lists" @selection-change="handleSelectionChange">
					<el-table-column type="selection" width="55" />
					<el-table-column label="用户" min-width="150">
						<template #default="{ row }">
							<div>账号：{{row.mobile}}</div>
							<div>邀请码：{{row.u_sn}}</div>
						</template>
					</el-table-column>
					<el-table-column label="分类名称" prop="cate_name" show-overflow-tooltip />
					<el-table-column label="反馈内容" prop="content" show-overflow-tooltip />
					<el-table-column label="反馈时间" prop="create_time" show-overflow-tooltip />
					<el-table-column label="操作" width="120" fixed="right">
						<template #default="{ row }">
							<el-button v-perms="['feedback.feedback_record/delete']" type="danger" link
								@click="handleDelete(row.id)">
								删除
							</el-button>
						</template>
					</el-table-column>
				</el-table>
			</div>
			<div class="flex mt-4 justify-end">
				<pagination v-model="pager" @change="getLists" />
			</div>
		</el-card>
	</div>
</template>

<script lang="ts" setup name="feedbackRecordLists">
	import { usePaging } from '@/hooks/usePaging'
	import { useDictData } from '@/hooks/useDictOptions'
	import { apiFeedbackRecordLists, apiFeedbackRecordDelete } from '@/api/feedback_record'
	import feedback from '@/utils/feedback'

	// 查询条件
	const queryParams = reactive({

	})

	// 选中数据
	const selectData = ref<any[]>([])

	// 表格选择后回调事件
	const handleSelectionChange = (val : any[]) => {
		selectData.value = val.map(({ id }) => id)
	}

	// 获取字典数据
	const { dictData } = useDictData('')

	// 分页相关
	const { pager, getLists, resetParams, resetPage } = usePaging({
		fetchFun: apiFeedbackRecordLists,
		params: queryParams
	})

	// 删除
	const handleDelete = async (id : number | any[]) => {
		await feedback.confirm('确定要删除？')
		await apiFeedbackRecordDelete({ id })
		getLists()
	}

	getLists()
</script>